#include <network/net_interface.h>

#include "config.h"
#include "utils.h"
void config_terminal_read(dictionary *d, char* sec_name, config_terminal_t *terminal)
{
	terminal->id = iniparser_sec_getint(d, sec_name, "id", 0xFFFFFFFF);
	strncpy(terminal->password, iniparser_sec_getstring(d, sec_name, "password", NULL), sizeof(terminal->password));
	strncpy(terminal->phone, iniparser_sec_getstring(d, sec_name, "phone", NULL), sizeof(terminal->phone));
}

void config_address_read(dictionary *d, char* sec_name, config_address_t *addr)
{
	char *buffer;
	strncpy(addr->apn, iniparser_sec_getstring(d, sec_name, "apn", ""), sizeof(addr->apn));
	buffer = iniparser_sec_getstring(d, sec_name, "type", "udp");
	if (strcmp(buffer, "tcp") == 0)
	{
		addr->type = NET_TCP;
	}
	else if (strcmp(buffer, "udp") == 0)
	{
		addr->type = NET_UDP;
	}
	else
	{
		addr->type = NET_NONE;
	}
	buffer = iniparser_sec_getstring(d, sec_name, "ip", "127.0.0.1");
	addr->ip = str2ip(buffer);
	addr->port = iniparser_sec_getint(d, sec_name, "port", 1001);
	strncpy(addr->phone, iniparser_sec_getstring(d, sec_name, "phone", ""), sizeof(addr->phone));
}
